package basetest.wsf

import scala.actors.Actor
import scala.actors.Actor._

/**
  * Created by shouf on 2016/5/11.
  * ????Acotr?????????
  * ?????????????????????????act????
  * ????actor?????????
  */
object ActorTest2 extends App {
  val actor_a: Actor = actor{
    while (true){
      receive {
        case msg => println("actor_a   " + msg)
      }
    }
  }

  val actor_b = actor{//???????act????
    while (true){
      receive {
        case msg => {
          println("actor_b   " + msg)
          actor_a ! "b  ---- >>>  a" //?????????????receive????????actor?з??????
          sender ! "receive  " + msg  //???sender????????????????????????
        }
      }
    }
  }

  actor_a ! "wsf"  //??actor?????????  ????????
  actor_b ! Math.PI

  self.receive{case msg=>println(msg)}  //???self.receive????actor????????
//  self.reactWithin(1000){case msg=>println(msg)}  //?????????

  actor3.start()
  actor3 ! "wsf  333"
  actor3 ! "wsf  333"
  actor3 ! "wsf  333"
}

object actor3 extends Actor{
  def act: Unit ={
//    react{//??????  ??act?????????react  ?????????????  ???????case??????????act  ??????????loop
//      case msg=>
//        println(msg)
//        sender ! msg
//        act
//      case _ => println("exit")
//    }
    loop{
      react{
              case msg=>
                println(msg)
                sender ! msg
              case _ => println("exit")
      }
    }
  }
}
